package cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.controller;

import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.entity.Monograph;
import cn.edu.sdjzu.xg.eagle.xg23_kcsj_01.service.MonographService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/monographs")
public class MonographController {

    @Autowired
    private MonographService monographService;

    @GetMapping("/monographs")
    public PageInfo<Monograph> get(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize,
            Monograph monograph) {
        return monographService.get(pageNum, pageSize, monograph);
    }

    @PostMapping("/monographs")
    public String save(@RequestBody Monograph monograph) {
        return monographService.save(monograph);
    }

    @PutMapping("/monographs")
    public String update(@RequestBody Monograph monograph) {
        return monographService.update(monograph);
    }

    @DeleteMapping("/{id}")
    public String delete(@PathVariable Long id) {
        return monographService.delete(id);
    }
}